﻿// ------------------------------------------------------------------------------
//  © 2008 OpenUpon™.  All rights reserved.
// ------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using Castle.ActiveRecord;
using NHibernate.Expression;

namespace CastUpon.Entities {
	[ActiveRecord]
	public class Podcast : ActiveRecordBase<Podcast> {
		private string author;
		private PodcastChannel channel;
		private IList<Comment> comments;
		private string content;
		private string contentEncoded;
		private string description;
		private TimeSpan duration;
		private string filePath;
		private string fileSize;
		private string fileType;
		private int id;
		private string keywords;
		private DateTime publishDate;
		private string subTitle;
		private string title;

		[PrimaryKey]
		public int Id {
			get { return this.id; }
			set { this.id = value; }
		}

		[BelongsTo("ChannelId")]
		public PodcastChannel Channel {
			get { return this.channel; }
			set { this.channel = value; }
		}

		[Property]
		public string Title {
			get { return this.title; }
			set { this.title = value; }
		}

		[Property]
		public string SubTitle {
			get { return this.subTitle; }
			set { this.subTitle = value; }
		}

		[Property]
		public string ContentEncoded {
			get { return this.contentEncoded; }
			set { this.contentEncoded = value; }
		}

		public string ContentEncodedNoNewLines
		{
			get { return this.contentEncoded.Replace("\n", String.Empty).Replace("\r", String.Empty); }
		}

		[Property]
		public string Content {
			get { return this.content; }
			set { this.content = value; }
		}

		[Property]
		public DateTime PublishDate {
			get { return this.publishDate; }
			set { this.publishDate = value; }
		}

		[Property]
		public string Description {
			get { return this.description; }
			set { this.description = value; }
		}

		[Property]
		public string FilePath {
			get { return this.filePath; }
			set { this.filePath = value; }
		}

		[Property]
		public string FileSize {
			get { return this.fileSize; }
			set { this.fileSize = value; }
		}

		[Property]
		public string FileType {
			get { return this.fileType; }
			set { this.fileType = value; }
		}

		[Property]
		public TimeSpan Duration {
			get { return this.duration; }
			set { this.duration = value; }
		}

		[Property]
		public string Keywords {
			get { return this.keywords; }
			set { this.keywords = value; }
		}

		[Property]
		public string Author {
			get { return this.author; }
			set { this.author = value; }
		}

		//[HasMany(Inverse = true, Cascade = ManyRelationCascadeEnum.AllDeleteOrphan, Lazy = true)]
		[HasMany(Inverse = true, Cascade = ManyRelationCascadeEnum.AllDeleteOrphan)]
		public IList<Comment> Comments {
			get { return this.comments; }
			set { this.comments = value; }
		}

		public static Podcast GetPodcastByChannelAndId(int channelId, int podcastId) {
			return FindFirst(Expression.Conjunction().Add(Expression.Eq("Channel.Id", channelId)).Add(Expression.Eq("Id", podcastId)));
		}
	}
}